package com.snail.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.snail.model.pojo.media.BizWorks;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Date 2025/8/19 20:25
 * @Author yangming
 * @Description TODO
 **/
@Mapper
public interface BizWorksMapper extends BaseMapper<BizWorks> {
    @Select("""
        SELECT * FROM (
            -- file_md5去重
            SELECT 
                id, user_id, works_name, cover_file_url, description, 
                tags, is_charge, price, status, file_md5, 
                create_time, update_time, deleted
            FROM (
                SELECT 
                    *,
                    ROW_NUMBER() OVER (PARTITION BY file_md5 ORDER BY id) AS row_num
                FROM biz_works
                WHERE deleted = 0  
            ) AS sub 
            WHERE row_num = 1  
        ) AS distinct_works
        ORDER BY RAND()  
        LIMIT 6  -- 取6条
    """)
    List<BizWorks> selectDistinctByFileMd5Random6();
}
